package com.edt.ichannel.api.service.impl;

import cc.edt.iceutils2.string.IceStringUtils;
import com.edt.ichannel.api.dao.ProductDao;
import com.edt.ichannel.api.service.ProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class ProductServiceImpl implements ProductService{

    @Resource
    private ProductDao productDao;
    @Override
    @Transactional(propagation = Propagation.SUPPORTS ,rollbackFor = Exception.class)
    public String getProductIdByCode(String productCode) {
        if(IceStringUtils.isBlank(productCode)){
            return "";
        }
        String productId = selectIdFromProduct(productCode);
        if(IceStringUtils.isBlank(productId)){
            productId = selectIdFromProductSub(productCode);
        }
        return IceStringUtils.blankToDefault(productId,"");
    }

    @Override
    public String selectIdFromProduct(String productCode) {
        return productDao.selectIdFromProduct(productCode);
    }

    @Override
    public String selectIdFromProductSub(String productCode) {
        return productDao.selectIdFromProductSub(productCode);
    }
}
